﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Web;

namespace Stamp_For_Africa_Version_2.Models
{
  public partial class Currency
  {
    public bool IsValid
    {
      get { return (GetRuleViolations().Count() == 0); }
    }

    public IEnumerable<RuleViolation> GetRuleViolations()
    {
      if (String.IsNullOrEmpty(CurrencyText))
        yield return new RuleViolation("Currency text required", "CurrencyText");

			if (!String.IsNullOrEmpty(CurrencyText))
			{
				if (CurrencyText.Length > 10)
					yield return new RuleViolation("Currency text is longer than 10 chars. Please enter the abriviated value for the currency", "CurrencyText");
			}

      if (String.IsNullOrEmpty(DisplayName))
        yield return new RuleViolation("Display name required", "DisplayName");

      yield break;
    }

    partial void OnValidate(ChangeAction action)
    {
      if (!IsValid)
        throw new ApplicationException("Rule violations prevent saving");
    }

		public override string ToString()
		{
			return DisplayName;
		}
  }
}